package com.ty.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ty.system.mapper.CoachMapper;
import com.ty.system.domain.Coach;
import com.ty.system.service.ICoachService;
import org.springframework.util.CollectionUtils;

/**
 * 教练Service业务层处理
 *
 * @author
 * @date 2024-05-26
 */
@Service
public class CoachServiceImpl implements ICoachService
{
    @Autowired
    private CoachMapper coachMapper;

    /**
     * 查询教练
     *
     * @param id 教练主键
     * @return 教练
     */
    @Override
    public Coach selectCoachById(Long id)
    {
        return coachMapper.selectCoachById(id);
    }

    /**
     * 查询教练列表
     *
     * @param coach 教练
     * @return 教练
     */
    @Override
    public List<Coach> selectCoachList(Coach coach)
    {
        return coachMapper.selectCoachList(coach);
    }

    /**
     * 新增教练
     *
     * @param coach 教练
     * @return 结果
     */
    @Override
    public int insertCoach(Coach coach)
    {
        List<String> list = coach.getDrivingLicenseTypeList();
        if(!CollectionUtils.isEmpty(list)){
            coach.setDrivingLicenseType(String.join(",",list));
        }else {
            coach.setDrivingLicenseType("");
        }
        return coachMapper.insertCoach(coach);
    }

    /**
     * 修改教练
     *
     * @param coach 教练
     * @return 结果
     */
    @Override
    public int updateCoach(Coach coach)
    {
        List<String> list = coach.getDrivingLicenseTypeList();
        if(!CollectionUtils.isEmpty(list)){
            coach.setDrivingLicenseType(String.join(",",list));
        }else {
            coach.setDrivingLicenseType("");
        }
        return coachMapper.updateCoach(coach);
    }

    /**
     * 批量删除教练
     *
     * @param ids 需要删除的教练主键
     * @return 结果
     */
    @Override
    public int deleteCoachByIds(Long[] ids)
    {
        return coachMapper.deleteCoachByIds(ids);
    }

    /**
     * 删除教练信息
     *
     * @param id 教练主键
     * @return 结果
     */
    @Override
    public int deleteCoachById(Long id)
    {
        return coachMapper.deleteCoachById(id);
    }
}
